#ifndef _IFCS_
#define _IFCS_

#include "hge\hge.h"
#include "hge\hgesprite.h"
#include "hge\hgecolor.h"
#include "hge\hgevector.h"

class IFCS;

struct Ammo {
	Ammo(): ifcs(0), next(0), prev(0) {}
	Ammo(float x0, float y0, float _vx, float _vy)
		: ifcs(0), next(0), prev(0),
		x(x0), y(y0), vx(_vx), vy(_vy), color(0xffffffff), life(3.f) {
			hgeVector a(vx, vy);
			hgeVector n(0, 1);
			rot = a.Angle(&n);
			if (vx > 0) rot = -rot;
	}

	virtual bool update(float dt)
	{
		if ((life -= dt) < 0)  return true;
		else {
			if (life / 3.f < 0.5) {
				color = (int(life / 1.5 * 255) << 24) + 0xffffff; 
			}
		}
		x += vx * 200 * dt;
		y += vy * 200 * dt;
		return false;
	}
	virtual void render() {
		spr->SetColor(color);
		spr->RenderEx(x, y, rot, 0.4f, 0.4f);
	}

	Ammo *next, *prev;
	float life;
	float x, y, vx, vy, rot;
	IFCS* ifcs;
	static hgeSprite* spr;
	DWORD color;
};

class IFCS {
public:
	IFCS();
	~IFCS();
	void addAmmo(Ammo* amm);
	Ammo* removeAmmo(Ammo* amm);
	void Update(float dt);
	void Render();
	int getAmmoAlive() { return count; }
private:
	Ammo *head, *tail;
	int count;
};

#endif